<template>
	<view class="y">
		<!-- 搜索框 -->
		<div style="margin: 12px;">
			<input type="text" class="search" placeholder="搜索" />
		</div>
		<div class="x">

			<!-- 左边 -->
			<div class="y" style="width: 20%;">
				<div class="s2" v-for="(item,index) in shu" :key="index">
					<view :class="{'yanse' : banduan===infex}" @click="dian(item.id,index)">{{item.name}}</view>
				</div>
			</div>
			<!-- 右边 -->
			<div class="y" style="width: 80%;">
				<image :src="sun.picUrl" style="margin: 9px;height: 100px;"></image>
				<view style="margin: 12px 30px;">{{sun.desc}}</view>

				<view class="x" style="flex-wrap: wrap;padding: 12px;">
					<view v-for="(item,index) in lan" :key="index">
						<image :src="item.picUrl" class="s4"></image>
						<view style="margin-left: 30px;text-align: center;font-size: 12px;">{{item.name}}</view>
					</view>
				</view>
			</div>
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				banduan: 0,
				sun: [],
				shu: [],
				lan: []
			}
		},
		onLoad() {
			uni.request({
				url: 'http://47.91.230.137:8086/wx/catalog/index', //仅为示例，并非真实接口地址。
				success: (res) => {
					console.log(res)
					this.sun = res.data.data.currentCategory
					this.shu = res.data.data.categoryList
					this.lan = res.data.data.currentSubCategory
				}
			})
		},
		methods: {
			dian(id, index) {
				this.banduan = index
				uni.request({
					url: 'http://47.91.230.137:8086/wx/catalog/current?id=' + id, //仅为示例，并非真实接口地址。
					success: (res) => {
						console.log(res)
						this.sun = res.data.data.currentCategory
						this.lan = res.data.data.currentSubCategory
					}
				})

			}
		},
	}
</script>

<style>
	.search {
		height: 36px;
		border-radius: 18px;
		border: 1px solid #ccc;
		padding-left: 20px;
		background-color: #fff;
	}

	.s2 {
		padding: 15px;
		border-bottom: 1px solid #ccc;

	}

	.yansee {
		color: blueviolet;

	}

	.s4 {
		width: 70px;
		height: 70px;
		padding-left: 30px;
	}
</style>